package cn.zhpdmmz.service.impl;

import cn.zhpdmmz.entity.Customer;
import cn.zhpdmmz.mapper.CustomerMapper;
import cn.zhpdmmz.service.ICustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Customer)表服务实现类
 *
 * @author CJW
 * @since 2022-04-03 18:44:55
 */
@Service("customerService")
public class CustomerServiceImpl implements ICustomerService {
    @Resource
    private CustomerMapper customerMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param customerId 主键
     * @return 实例对象
     */
    @Override
    public Customer queryById(Integer customerId) {
        return this.customerMapper.queryById(customerId);
    }

    /**
     * 查询指定行
     *
     * @param customer 筛选条件
     * @return 查询结果
     */
    @Override
    public List<Customer> queryAll(Customer customer) {
        return this.customerMapper.queryAll(customer);
    }

    /**
     * 新增数据
     *
     * @param customer 实例对象
     * @return 实例对象
     */
    @Override
    public Customer insert(Customer customer) {
        this.customerMapper.insert(customer);
        return customer;
    }

    /**
     * 修改数据
     *
     * @param customer 实例对象
     * @return 实例对象
     */
    @Override
    public Customer update(Customer customer) {
        this.customerMapper.update(customer);
        return this.queryById(customer.getCustomerId());
    }

    /**
     * 通过主键删除数据
     *
     * @param customerId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer customerId) {
        return this.customerMapper.deleteById(customerId) > 0;
    }
}
